<?php
require_once("funcionesBase.php");

echo '			<div class="modal fade" id="modeloMensaje" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-dialog moMensaje">
							<div class="modal-content moMensaje" id="cuerpoMensaje">
								
							</div>
							
						</div>
					</div>';


echo '			<div class="modal fade" id="modeloNuevaTabla" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-dialog moNuevaTabla">
							<div class="modal-content moNuevaTabla" id="cuerpoNuevaTabla">
								
							</div>
							
						</div>
					</div>';



echo '


<div class="panel panel-primary">
					
					
					<div class="panel-heading">
						<div class="row">
							<div class="col-md-5">
								<span class="glyphicon glyphicon-list-alt"></span>
									Tablas
							</div>
							<div class="col-md-15 tdDerecha">
								<button id="btnNuevaTabla" type="button" class="btn btn-success tdDerecha btn-sm" data-toggle="modal" data-target="#modeloNuevaTabla" >
											<span class="glyphicon glyphicon-plus-sign"></span>
											Nueva tabla
								</button>
							</div>
						</div>
						

						
					</div>';
 

$tablas= getTablas();
while($unaTabla = mysql_fetch_array($tablas)) {
	echo '
		<br>
		<div class="panel panel-info tdCentrado ">
				<div class="panel-heading">
				
					<div class="row">
						<div class="col-md-1">
						<IMG SRC="img/img_tabla.png"></span>
						</div>
						<div class="col-md-4">';
	echo ''.$unaTabla[0]; 
	echo '				<span class="badge">'.getNumTuplas($unaTabla[0]).' tuplas</span>
							</div>
							<div class="col-md-15 tdDerecha">
								<div class="btn-group">
									<button type="button" class="btn btn-info btn-sm" '.
									'id="tuplas_'.$unaTabla[0].'">
										<span class="glyphicon glyphicon-eye-open"></span>
										Tuplas
									</button>
									<button type="button" class="btn btn-primary btn-sm" '.
									'id="modificar'.$unaTabla[0].'">
										<span class="glyphicon glyphicon-edit"></span>
										Modificar estructura
									</button>
									<button type="button" class="btn btn-warning btn-sm" '.
									'id="vaciar'.$unaTabla[0].'" data-toggle="modal" data-target="#modeloMensaje"
									disabled="disabled">
										<span class="glyphicon glyphicon-fire"></span>
										Vaciar
									</button>
									<button type="button" class="btn btn-danger btn-sm" '.
									'id="eliminar'.$unaTabla[0].'" data-toggle="modal" data-target="#modeloMensaje">
										<span class="glyphicon glyphicon-trash"></span>
										Eliminar
									</button>
								</div>
							</div>
						</div>
						
					</div>
					<table class="table table-striped table-hover table-bordered table-condensed">
                        
                        <tr>
							<th>Nombre de columna</th>
							<th>Tipo</th>
							<th>Longitud</th>
							<th>Valores Null</th>
							<th>Clave primaria</th>
							<th>AutoIncrement</th>
                        </tr>
					';
		$columnas= getColumnas( $unaTabla[0] );
		while($unaColumna = mysql_fetch_array($columnas)) {
					echo	'<tr>';
					echo	'<td>'.$unaColumna['Field'].'</td>';
					echo	'<td>'.getNombreTipo($unaColumna['Type']).'</td>';
					echo	'<td>'. getLongitud($unaColumna['Type']).'</td>';
					/*echo	'<td>'.  $unaColumna['Null'] .'</td>';
					echo	'<td>'. $unaColumna['Key'] .'</td>';
					
					echo	'<td>'. $unaColumna['Extra'] .'</td>';
					*/
					
					if ( $unaColumna['Null'] == "NO" )
					{
						echo	'<td><IMG SRC="img/img_x.png"></td>';	
						
						}
					else
					{
						echo	'<td><IMG SRC="img/img_ok.png"></td>';		
						}
					
					
					
					if ( $unaColumna['Key'] != "PRI" )
					{
						echo	'<td><IMG SRC="img/img_x.png"></td>';	
						
						}
					else
					{
						echo	'<td><IMG SRC="img/img_ok.png"></td>';		
						}
					
					if ( $unaColumna['Extra'] != "auto_increment" )
					{
						echo	'<td><IMG SRC="img/img_x.png"></td>';	
						
						}
					else
					{
						echo	'<td><IMG SRC="img/img_ok.png"></td>';		
						}
					
					
                    echo '</tr>';				
		}
		echo '</table>';		
		echo '</div>';

echo '
	<script>	
	$( "#eliminar'.$unaTabla[0].'" ).mousedown(function() {
		$( "#cuerpoMensaje" ).load("elTabla.php?tablaAEliminar='.$unaTabla[0].'");
		
	});
	$( "#vaciar'.$unaTabla[0].'" ).mousedown(function() {
		$( "#cuerpoMensaje" ).load("vaciarTabla.php?tablaAVaciar='.$unaTabla[0].'");
		
	});
	$( "#modificar'.$unaTabla[0].'" ).mousedown(function() {
		$( "#cuerpoPrincipal" ).load("mostrarColumnas.php?tablaAModificar='.$unaTabla[0].'");
		
	});
	$( "#tuplas_'.$unaTabla[0].'" ).mouseup(function() {
		$( "#cuerpoPrincipal" ).load("tuplas.php?tabla='.$unaTabla[0].'");
		
	});

	</script>
';

		
}
echo '
	<script>	
	$( "#btnNuevaTabla" ).mousedown(function() {
		$( "#cuerpoNuevaTabla" ).load("nuevaTabla1.php");
		
	});
	
	</script>
';

?>

